fi.internetix.s2nq.NotificationQueue = Class.create({
  initialize: function (options) {
    this._options = Object.extend({
    }, options || {});
    
    this.domNode = new Element("div", {
      className: "notificationQueue"
    });
    
    this._itemsContainer = new Element("div", {
      className: "notificationQueueItemsContainer"
    });
    
    this.domNode.appendChild(this._itemsContainer);
    
    this._items = new Array(); 
  },
  addItem: function (notificationQueueItem) {
    if (this._items.length > 0) {
      this._items[this._items.length - 1].domNode.removeClassName("notificationQueueItemLast");
    }
    
    this._items.push(notificationQueueItem);
    this._itemsContainer.appendChild(notificationQueueItem.domNode);
    notificationQueueItem.domNode.addClassName("notificationQueueItemLast");
    
    notificationQueueItem.setup(this);
    
    return notificationQueueItem;
  },
  removeItem: function (notificationQueueItem) {
    for (var i = 0, l = this._items.length; i < l; i++) {
      if (this._items[i] === notificationQueueItem) {
        this._items.splice(i, 1);
        break;
      }
    }
    
    if (this._items.length > 0) {
      this._items[this._items.length - 1].domNode.addClassName("notificationQueueItemLast");
    }
    
    var height = notificationQueueItem.domNode.getDimensions().height;
    
    notificationQueueItem.domNode.setStyle({
      zIndex: 0
    });
    
    // TODO: Remove this when scripty2 fixes accelerated effects on Firefox
    var engine = Prototype.Browser.WebKit ? 'css-transition' : 'javascript';
    
    new S2.FX.Morph(notificationQueueItem.domNode, {
      style: "margin-top: -" + height + 'px',
      engine: engine,
       duration: 0.6,
      after: function(){
        notificationQueueItem.deinitialize();
      }
    }).play();
  }
});